/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package l1j.server.server.model.Instance;

import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.opqlo.NewSystem.Attack.L1AttackModel;
import l1j.opqlo.NewSystem.Attack.L1AttackPc;
import l1j.opqlo.Server.L1World.L1World;
import l1j.opqlo.Server.L1World.WorldClan;
import l1j.server.Thread.GeneralThreadPool;
import l1j.server.server.ActionCodes;
import l1j.server.server.datatables.NPCTalkDataTable;
import l1j.server.server.datatables.SprTable;
import l1j.server.server.model.L1CastleLocation;
import l1j.server.server.model.L1Character;
import l1j.server.server.model.L1Clan;
import l1j.server.server.model.L1Location;
import l1j.server.server.model.L1NpcTalkData;
import l1j.server.server.model.L1Object;
import l1j.server.server.model.L1Teleport;
import l1j.server.server.serverpackets.S_DoActionGFX;
import l1j.server.server.serverpackets.S_NPCTalkReturn;
import l1j.server.server.serverpackets.S_NpcChatPacket;
import l1j.server.server.serverpackets.S_RemoveObject;
import l1j.server.server.templates.L1Npc;
import l1j.server.server.types.Point;
import l1j.server.server.utils.Random;
import static l1j.server.server.model.skill.L1SkillId.*;

public class L1GuardInstance extends L1NpcInstance {
	private static final Logger _log = Logger.getLogger(L1GuardInstance.class.getName());
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int _randomMoveDistance = 0;

	private int _randomMoveDirection = 0;

	private long srctime = System.currentTimeMillis();

	// ターゲットを探す
	@Override
	public void searchTarget() {//opqlo 警衛不追紅人
		// ターゲット捜索
		if(this.getNpcId() == 710061){

			L1PcInstance targetPlayer = null;
			for (final L1PcInstance pc : L1World.getInstance().getVisiblePlayer(this)) {
				if ( pc.getCurrentHp() <= 0 || pc.isDead() || pc.isGm()|| pc.isGhost() || !pc.isWanted() ) {
					continue;
				}
				//				if (!pc.isInvisble() || getNpcTemplate().is_agrocoi()){ // インビジチェック
				//				if (pc.isWanted()) { // PKで手配中か
				final int pkcount = pc.get_PKcount();
				if (
						!pc.hasSkillEffect(SHOCK_STUN) && 
						!pc.hasSkillEffect(STATUS_FREEZE) && 
						!pc.hasSkillEffect(EARTH_BIND) &&
						!pc.hasSkillEffect(ICE_LANCE) &&
						!pc.hasSkillEffect(FREEZING_BLIZZARD) &&
						!pc.hasSkillEffect(FREEZING_BREATH) &&
						!pc.hasSkillEffect(CURSE_PARALYZE)&&
						!pc.hasSkillEffect(CURSE_PARALYZE2)&&
						!pc.hasSkillEffect(ALL_PARALYZE)
						){ // インビジチェック
					targetPlayer = pc;
					if(pkcount >=30){
						pc.sendPacketsAll(new S_NpcChatPacket(this, "通緝犯["+pc.getName()+"]殺了"+pkcount+"人,應服刑"+pkcount*30+"分鐘。", 2));
					}else{
						pc.sendPacketsAll(new S_NpcChatPacket(this, "$815", 2)); // 同族を殺したものは、己の血でその罪をあがなうことになるだろう
					}
					this.setSkillEffect(STATUS_FREEZE, 5000);
					setPassispeed(getNpcTemplate().get_passispeed()*5);
					break;
					//					}
				}
			}
			final long nowtime = System.currentTimeMillis();
			if (targetPlayer != null) {
				_hateList.add(targetPlayer, 0);
				_target = targetPlayer;
				srctime  = nowtime;
			}else if(nowtime - srctime >= 20000){
				randomTeleport();
				srctime = nowtime;
			}
		}
	}

	public void setTarget(final L1PcInstance targetPlayer) {
		if (targetPlayer != null) {
			_hateList.add(targetPlayer, 0);
			_target = targetPlayer;
		}
	}


	// ターゲットがいない場合の処理
	@Override
	public boolean noTarget() {
		if(this.getNpcId() == 710061){

			if(this.getTempCharGfx() == 539){
				final int gfxid = this.getGfxId();
				setTempCharGfx(gfxid);
				setPassispeed(SprTable.getInstance().getMoveSpeed(gfxid, 0));
				for (final L1PcInstance pc : L1World.getInstance().getRecognizePlayer(this)) {
					pc.sendPackets(new S_RemoveObject(this));
					pc.removeKnownObject(this);
					pc.updateObject();
				}
			}else if(this.hasSkillEffect(巡守變身)){
				this.killSkillEffectTimer(巡守變身);
			}

			// 如果移動距離已經為0 重新定義隨機移動
			if (this._randomMoveDistance == 0) {

				// 產生移動距離
				this._randomMoveDistance = Random.nextInt(3) + 1;

				// 產生移動方向(隨機數值超出7物件會暫停移動)
				this._randomMoveDirection = Random.nextInt(40);

				//				// 返回出生點的判斷
				//				if (this.getHomeX() != 0 && this.getHomeY() != 0// 具有出生點設置
				//						&& this._randomMoveDirection < 8// 具有移動方向
				//						/*&& (_random.nextInt(3) == 0)*/) {// 隨機產生0
				//					if (this._npcMove != null) {
				//						this._randomMoveDirection = this._npcMove.moveDirection(this.getHomeX(), this.getHomeY());
				//					}
				//				}

			} else {
				this._randomMoveDistance--;
			}

			if (this._npcMove != null) {
				if (this._randomMoveDirection < 8) {
					int dir = this._npcMove.checkObject(this._randomMoveDirection);
					dir = this._npcMove.openDoor(dir);

					if (dir != -1) {
						this._npcMove.setDirectionMove(dir);
						this.setSleepTime(this.calcSleepTime(this.getPassispeed(), MOVE_SPEED));
					}
				}
			}
		}else{
			if (this.getLocation().getTileLineDistance(new Point(getHomeX(), getHomeY())) > 0) {
				if (_npcMove != null) {
					final int dir = _npcMove.moveDirection(getHomeX(), getHomeY());
					if (dir != -1) {
						_npcMove.setDirectionMove(dir);
						setSleepTime(calcSleepTime(getPassispeed(), MOVE_SPEED));
					} else {
						teleport(getHomeX(), getHomeY(), 1);
					}
				}
			} else {
				if (L1World.getInstance().getRecognizePlayer(this).size() == 0) {
					return true; // 周りにプレイヤーがいなくなったらＡＩ処理終了
				}
			}
		}
		return false;
	}


	public L1GuardInstance(final L1Npc template) {
		super(template);
	}

	@Override
	public void onNpcAI() {
		if (isAiRunning()) {
			return;
		}
		setActived(false);
		startAI();
	}

	@Override
	public void onAction(final L1PcInstance pc) {
		if (!isDead()) {
			if (getCurrentHp() > 0) {
				final L1AttackModel attack = new L1AttackPc(pc, this);
				if (attack.calcHit()) {
					attack.calcDamage();
					attack.calcStaffOfMana();
					attack.addChaserAttack();
				}
				attack.action();
				attack.commit();
			} else {
				final L1AttackModel attack = new L1AttackPc(pc, this);
				attack.calcHit();
				attack.action();
			}
		}
	}

	@Override
	public void onTalkAction(final L1PcInstance player) {
		final int objid = getId();
		final L1NpcTalkData talking = NPCTalkDataTable.getInstance().getTemplate(getNpcTemplate().get_npcId());
		final int npcid = getNpcTemplate().get_npcId();
		String htmlid = null;
		String[] htmldata = null;
		boolean hascastle = false;
		String clan_name = "";
		String pri_name = "";

		if (talking != null) {
			// キーパー
			if (npcid == 70549 || // ケント城左外門キーパー
					npcid == 70985) { // ケント城右外門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.KENT_CASTLE_ID);
				if (hascastle) { // 城主クラン員
					htmlid = "gateokeeper";
					htmldata = new String[] { player.getName() };
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70656) { // 肯特內城門
				hascastle = checkHasCastle(player,L1CastleLocation.KENT_CASTLE_ID);
				if (hascastle) { // 城主クラン員
//					htmlid = "gatekeeper";
//					htmldata = new String[] { player.getName() };
					htmlid ="";
					L1Teleport.teleportByMagic(player, 32736,32803,(short)15, player.getHeading(), true);
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70600 || npcid == 70986) {// オークの森外門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.OT_CASTLE_ID);
				if (hascastle) { // 城主クラン員
					htmlid = "orckeeper";
				} else {
					htmlid = "orckeeperop";
				}
			} else if (npcid == 70687 || npcid == 70987) {// ウィンダウッド城外門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.WW_CASTLE_ID);
				if (hascastle) { // 城主クラン員
					htmlid = "gateokeeper";
					htmldata = new String[] { player.getName() };
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70778) { // ウィンダウッド城内門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.WW_CASTLE_ID);
				if (hascastle) { // 城主クラン員
					htmlid = "gatekeeper";
					htmldata = new String[] { player.getName() };
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70800 || npcid == 70988 || npcid == 70989 || npcid == 70990|| npcid == 70991) {// ギラン城外門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.GIRAN_CASTLE_ID);
				if (hascastle) { // 城主クラン員
					htmlid = "gateokeeper";
					htmldata = new String[] { player.getName() };
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70817) { // ギラン城内門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.GIRAN_CASTLE_ID);
				if (hascastle) { // 城主クラン員
//					htmlid = "gatekeeper";
//					htmldata = new String[] { player.getName() };
					htmlid = "";
						L1Teleport.teleportByMagic(player, 32726,32821,(short)52, player.getHeading(), true);
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70862 || npcid == 70992) {// ハイネ城外門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.HEINE_CASTLE_ID);
				if (hascastle) { // 城主クラン員
					htmlid = "gateokeeper";
					htmldata = new String[] { player.getName() };
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70863) { // ハイネ城内門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.HEINE_CASTLE_ID);
				if (hascastle) { // 城主クラン員
//					htmlid = "gatekeeper";
//					htmldata = new String[] { player.getName() };
					htmlid = "";
						L1Teleport.teleportByMagic(player, 32572,32849,(short)64, player.getHeading(), true);
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70993 || npcid == 70994) {// ドワーフ城外門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.DOWA_CASTLE_ID);
				if (hascastle) { // 城主クラン員
					htmlid = "gateokeeper";
					htmldata = new String[] { player.getName() };
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70995) { // ドワーフ城内門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.DOWA_CASTLE_ID);
				if (hascastle) { // 城主クラン員
					htmlid = "gatekeeper";
					htmldata = new String[] { player.getName() };
				} else {
					htmlid = "gatekeeperop";
				}
			} else if (npcid == 70996) { // アデン城内門キーパー
				hascastle = checkHasCastle(player,L1CastleLocation.ADEN_CASTLE_ID);
				if (hascastle) { // 城主クラン員
					htmlid = "gatekeeper";
					htmldata = new String[] { player.getName() };
				} else {
					htmlid = "gatekeeperop";
				}
			}

			// 近衛兵
			else if (npcid == 60514) { // ケント城近衛兵
				for (final L1Clan clan : WorldClan.get().getAllClans()) {
					if (clan.getCastleId() == L1CastleLocation.KENT_CASTLE_ID) {// 城主クラン
						clan_name = clan.getClanName();
						pri_name = clan.getLeaderName();
						break;
					}
				}
				htmlid = "ktguard6";
				htmldata = new String[] { getName(), clan_name, pri_name };
			} else if (npcid == 60560) { // オーク近衛兵
				for (final L1Clan clan : WorldClan.get().getAllClans()) {
					if (clan.getCastleId() == L1CastleLocation.OT_CASTLE_ID) {// 城主クラン
						clan_name = clan.getClanName();
						pri_name = clan.getLeaderName();
						break;
					}
				}
				htmlid = "orcguard6";
				htmldata = new String[] { getName(), clan_name, pri_name };
			} else if (npcid == 60552) { // ウィンダウッド城近衛兵
				for (final L1Clan clan : WorldClan.get().getAllClans()) {
					if (clan.getCastleId() == L1CastleLocation.WW_CASTLE_ID) {// 城主クラン
						clan_name = clan.getClanName();
						pri_name = clan.getLeaderName();
						break;
					}
				}
				htmlid = "wdguard6";
				htmldata = new String[] { getName(), clan_name, pri_name };
			} else if (npcid == 60524 || // ギラン街入り口近衛兵(弓)
					npcid == 60525 || // ギラン街入り口近衛兵
					npcid == 60529) { // ギラン城近衛兵
				for (final L1Clan clan : WorldClan.get().getAllClans()) {
					if (clan.getCastleId() == L1CastleLocation.GIRAN_CASTLE_ID) {// 城主クラン
						clan_name = clan.getClanName();
						pri_name = clan.getLeaderName();
						break;
					}
				}
				htmlid = "grguard6";
				htmldata = new String[] { getName(), clan_name, pri_name };
			} else if (npcid == 70857) { // ハイネ城ハイネ ガード
				for (final L1Clan clan : WorldClan.get().getAllClans()) {
					if (clan.getCastleId() == L1CastleLocation.HEINE_CASTLE_ID) {// 城主クラン
						clan_name = clan.getClanName();
						pri_name = clan.getLeaderName();
						break;
					}
				}
				htmlid = "heguard6";
				htmldata = new String[] { getName(), clan_name, pri_name };
			} else if (npcid == 60530 || // ドワーフ城ドワーフ ガード
					npcid == 60531) {
				for (final L1Clan clan : WorldClan.get().getAllClans()) {
					if (clan.getCastleId() // 城主クラン
							== L1CastleLocation.DOWA_CASTLE_ID) {
						clan_name = clan.getClanName();
						pri_name = clan.getLeaderName();
						break;
					}
				}
				htmlid = "dcguard6";
				htmldata = new String[] { getName(), clan_name, pri_name };
			} else if (npcid == 60533 || // アデン城 ガード
					npcid == 60534) {
				for (final L1Clan clan : WorldClan.get().getAllClans()) {
					if (clan.getCastleId() // 城主クラン
							== L1CastleLocation.ADEN_CASTLE_ID) {
						clan_name = clan.getClanName();
						pri_name = clan.getLeaderName();
						break;
					}
				}
				htmlid = "adguard6";
				htmldata = new String[] { getName(), clan_name, pri_name };
			} else if (npcid == 81156) { // アデン偵察兵（ディアド要塞）
				for (final L1Clan clan : WorldClan.get().getAllClans()) {
					if (clan.getCastleId() // 城主クラン
							== L1CastleLocation.DIAD_CASTLE_ID) {
						clan_name = clan.getClanName();
						pri_name = clan.getLeaderName();
						break;
					}
				}
				htmlid = "ktguard6";
				htmldata = new String[] { getName(), clan_name, pri_name };
				/************************opqlo 城堡升級系統 *******************************/
			} else if (npcid == 710037){
				hascastle = checkHasCastle(player, L1CastleLocation.getCastleIdByArea(getLocation()));
				if (hascastle) {
					htmlid = "CastleHa";
					htmldata = new String[] { player.getName() };
				} else {
					htmlid = "gatekeeperop";
				}
				/************************opqlo 城堡升級系統 *******************************/
			}

			// html表示パケット送信
			if (htmlid != null) { // htmlidが指定されている場合
				if (htmldata != null) { // html指定がある場合は表示
					player.sendPackets(new S_NPCTalkReturn(objid, htmlid,htmldata));
				} else {
					player.sendPackets(new S_NPCTalkReturn(objid, htmlid));
				}
			} else {
				if (player.getLawful() < -1000) { // プレイヤーがカオティック
					player.sendPackets(new S_NPCTalkReturn(talking, objid, 2));
				} else {
					player.sendPackets(new S_NPCTalkReturn(talking, objid, 1));
				}
			}
		}
	}

	public void onFinalAction() {

	}

	public void doFinalAction() {

	}
	//TODO 警衛可以殺死 & 幫打 by 阿傑
	@Override
	public void ReceiveManaDamage(final L1Character attacker, final int mpDamage) {
		if(this.getNpcId() == 710061 || this.getNpcId() == 710037){
			return;
		}
		if (mpDamage > 0 && !isDead()) {

			setHate(attacker, mpDamage);
			onNpcAI();

			if (attacker instanceof L1PcInstance) {
				serchLink((L1PcInstance) attacker, getNpcTemplate().get_family());
			}

			int newMp = getCurrentMp() - mpDamage;
			if (newMp < 0) {
				newMp = 0;
			}
			setCurrentMp(newMp);
		}
	}

	@Override
	public void receiveDamage(final L1Character attacker, final int damage) { // 攻撃でＨＰを減らすときはここを使用
		if(this.getNpcId() == 710061 || this.getNpcId() == 710037){
			return;
		}
		//TODO 警衛可以殺死 & 幫打 by 阿傑
		if (getCurrentHp() > 0 && !isDead()) {
			//TODO 警衛可以殺死 & 幫打 by 阿傑
			if (damage >= 0) {
				// int Hate = damage / 10 + 10; // ダメージの１０分の１＋ヒットヘイト１０
				// setHate(attacker, Hate);
				setHate(attacker, damage);
				removeSkillEffect(FOG_OF_SLEEPING);
			}

			onNpcAI();
			// TODO 警衛可以殺死 & 幫打 by 阿傑
			if (attacker instanceof L1PcInstance) {
				serchLink((L1PcInstance) attacker, getNpcTemplate()
						.get_family());
			}
			//TODO 警衛可以殺死 & 幫打 by 阿傑
			if (attacker instanceof L1PcInstance && damage > 0) {
				final L1PcInstance player = (L1PcInstance) attacker;
				player.setPetTarget(this);
			}
			// TODO 警衛可以殺死 & 幫打 by 阿傑
			final int newHp = getCurrentHp() - damage;
			if (newHp <= 0 && !isDead()) {
				setCurrentHpDirect(0);
				setDead(true);
				_lastattacker = attacker;
				final Death death = new Death();
				GeneralThreadPool.getInstance().execute(death);
				// Death(attacker);
			}
			if (newHp > 0) {
				setCurrentHp(newHp);
			}
		} else if (!isDead()) {
			setDead(true);
			_lastattacker = attacker;
			final Death death = new Death();
			GeneralThreadPool.getInstance().execute(death);
			// Death(attacker);
		}
		//TODO 警衛可以殺死 & 幫打 by 阿傑
	}

	// TODO 警衛可以殺死 & 幫打 by 阿傑
	@Override
	public void setCurrentHp(final int i) {
		int currentHp = i;
		if (currentHp >= getMaxHp()) {
			currentHp = getMaxHp();
		}
		setCurrentHpDirect(currentHp);

		if (getMaxHp() > getCurrentHp()) {
			startHpRegeneration();
		}
	}

	//TODO 警衛可以殺死 & 幫打 by 阿傑

	// TODO 警衛可以殺死 & 幫打 by 阿傑
	@Override
	public void setCurrentMp(final int i) {
		int currentMp = i;
		if (currentMp >= getMaxMp()) {
			currentMp = getMaxMp();
		}
		setCurrentMpDirect(currentMp);
		if (getMaxMp() > getCurrentMp()) {
			startMpRegeneration();
		}
	}

	//TODO 警衛可以殺死 & 幫打 by 阿傑

	// TODO 警衛可以殺死 & 幫打 by 阿傑
	private L1Character _lastattacker;

	class Death implements Runnable {
		L1Character lastAttacker = _lastattacker;
		L1Object object = L1World.getInstance().findObject(getId());
		L1GuardInstance npc = (L1GuardInstance) object;

		@Override
		public void run() {
			setDeathProcessing(true);
			setCurrentHpDirect(0);
			setDead(true);
//			final int targetobjid = getId();
			//npc.getMap().setPassable(npc.getLocation(), true);
			getMap().setPassable(getLocation(), true);
			/*if (lastAttacker instanceof L1PcInstance)
				broadcastPacket(new S_AttackPacket((L1PcInstance)lastAttacker,targetobjid, 8));
			else
				broadcastPacket(new S_AttackPacketForNpc(lastAttacker,targetobjid, 8));*/
			broadcastPacketAll(new S_DoActionGFX(getId(), ActionCodes.ACTION_Die));
//			L1PcInstance player = null;
//			if (lastAttacker instanceof L1PcInstance) {
//				player = (L1PcInstance) lastAttacker;
//			} else if (lastAttacker instanceof L1PetInstance) {
//				player = (L1PcInstance) ((L1PetInstance) lastAttacker)
//						.getMaster();
//			} else if (lastAttacker instanceof L1SummonInstance) {
//				player = (L1PcInstance) ((L1SummonInstance) lastAttacker)
//						.getMaster();
//			}
//
//			if (player != null) {
//				final ArrayList<L1Character> targetList = _hateList.toTargetArrayList();
//				final ArrayList<Integer> hateList = _hateList.toHateArrayList();
//				final long exp = getExp();
//				CalcExp.calcExp(player, targetobjid, targetList, hateList, exp);
//
//				try {
//					final DropShareExecutor dropShareExecutor = new DropShare();
//					dropShareExecutor.dropShare(npc, dropTargetList, dropHateList);
//				} catch (final Exception e) {
//					e.printStackTrace();
//				}
//			}
			setDeathProcessing(false);
			L1GuardInstance.this.startChat(CHAT_TIMING_DEAD);
			allTargetClear();
			final DeleteNpc delete_timer = new DeleteNpc();
			GeneralThreadPool.getInstance().execute(delete_timer);
		}
	}

	class DeleteNpc implements Runnable {
		@Override
		public void run() {
			try {
				Thread.sleep(10000);
			} catch (final Exception e) {
				e.printStackTrace();
			}
			if (!isDead() || _destroyed) {
				return;
			}
			deleteMe();
		}
	}

	@Override
	public void setLink(final L1Character cha) {
		if (cha != null && _hateList.isEmpty()) {
			_hateList.add(cha, 0);
			checkTarget();
		}
	}
	//TODO 警衛可以殺死 & 幫打by 阿傑

	private boolean checkHasCastle(final L1PcInstance pc, final int castleId) {
		if(pc.getClanid() ==0){
			return false;
		}else{
			boolean isExistDefenseClan = false;
			for (final L1Clan clan : WorldClan.get().getAllClans()) {
				if (castleId == clan.getCastleId()) {
					isExistDefenseClan = true;
					break;
				}
			}
			if (!isExistDefenseClan) { // 城主クランが居ない
				return true;
			}

			if (pc.getClanid() != 0) { // クラン所属中
				final L1Clan clan = WorldClan.get().getClan(pc.getClanname());
				if (clan != null) {
					if (clan.getCastleId() == castleId) {
						return true;
					}
				}
			}
		}
		return false;
	}

	/**
	 * 隨機執行移動
	 * @param pc
	 * @param effectable
	 */
	private void randomTeleport() {
		try {
			// まだ本サーバのランテレ処理と違うところが結構あるような・・・
			final L1Location newLocation = this.getLocation().randomLocation(200, true);
			final int newX = newLocation.getX();
			final int newY = newLocation.getY();
			this.teleport(newX, newY, 5);
			this.setSkillEffect(STATUS_FREEZE, 7000);
			this.setParalyzed(true);
		} catch (final Exception e) {
			_log.log(Level.SEVERE, e.getLocalizedMessage() , e);
		}
	}
}
